﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Practices.ServiceLocation;
using Microsoft.Practices.SharePoint.Common.ServiceLocation;

namespace SPWarmUp.Library
{
    public static class WarmUpServiceLocator
    {
        /// <summary>
        /// The IoC container
        /// </summary>
        public static IServiceLocator Container { get { return SharePointServiceLocator.GetCurrent(); } }

        public static T GetType<T>()
        {
            return Container.GetInstance<T>();
        }

        public static void RegisterType<TService, TClass>() where TClass : TService, new()
        {
            var config = GetType<IServiceLocatorConfig>();
            config.RegisterTypeMapping<TService, TClass>();
        }

        public static void UnregisterTypeMappings<T>()
        {
            var config = GetType<IServiceLocatorConfig>();
            config.RemoveTypeMappings<T>();
        }
    }
}
